import numpy as np
import pandas as pd
from pandas import Series,DataFrame

frame = DataFrame({'data1':np.random.randn(1000),
                  'data2':np.random.randn(1000)})

print frame
factor = pd.cut(frame.data1, 4)
print factor[:10]

def get_stats(group):
    return {'min':group.min(), 'max':group.max(), 'count':group.count(), 'mean':group.mean()}

grouped = frame.data2.groupby(factor)
print grouped.apply(get_stats).unstack()


print "------------------------1----------------------------"
states = ['Ohio', 'New York', 'Vermont', 'Florida', 'Oregon', 'Nevada', 'California', 'Idaho']
group_key = ['East']*4 + ['West']*4
print group_key
data = Series(np.random.randn(8), index=states)
print data

print data.groupby(group_key).mean()
print data.groupby(group_key).apply(lambda x : x.fillna(x.mean()))

suits = ['H', 'S', 'C', 'D']
card_val = (range(1, 11) + [10]*3*4)
